/*
 * @Author: asushiye
 * @Date: 2020-07-14 10:48:58
 * @Commit: file content
 */
import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { AfMessageService } from '@core';
import { STColumn, STComponent } from '@delon/abc/st';
import { SFSchema } from '@delon/form';
import { ModalHelper, _HttpClient } from '@delon/theme';
import { format } from 'sql-formatter';

import { CgExcelService } from '../cg-excel.service';

@Component({
  selector: 'app-db-script-log',
  templateUrl: './cg-db-script-log.component.html'
})
export class CgDbScriptLogComponent implements OnInit {
  req: any = { lazyLoad: true };
  queryParams: any;
  url = '';
  searchSchema: SFSchema;

  sqlformat(value: string) {
    if (value !== undefined) {
      let sql = format(value);
      // console.info(sql);
      return sql;
    }
    return '';
  }

  @ViewChild('st', { static: false }) st!: STComponent;

  columns: STColumn[] = [
    // { title: '编号', index: 'id' },
    // { title: '上传编号', index: 'sourceId' },
    { title: '序号', index: 'serial' },
    { title: '数据源', index: 'dbSourceName' },
    { title: '库类型', index: 'dbType' },
    { title: '表名称', index: 'tableName' },
    { title: '表注释', index: 'tableComment' },
    { title: '操作类型', index: 'scriptType' },
    {
      title: '操作状态',
      type: 'tag',
      index: 'scriptStatus',
      tag: {
        true: { text: '成功', color: 'success' },
        false: { text: '失败', color: 'orange' }
      }
    },
    // { title: '执行信息', index: 'scriptMsg' },
    { title: '执行时间', type: 'date', index: 'lastModifiedDate' }
    // {
    //   title: '',
    //   buttons: [
    //     {
    //       text: '查看脚本',
    //       tooltip: `查看脚本信息`,
    //       click: (_record) => {
    //         this.viewJson(_record);
    //       },
    //     },
    //   ]
    // }
  ];

  constructor(
    private route: ActivatedRoute,
    private msg: AfMessageService,
    private cgExcelService: CgExcelService,
    private modal: ModalHelper
  ) {
    this.queryParams = this.route.snapshot.queryParams;
    console.log(this.queryParams);

    this.searchSchema = {
      properties: {
        sourceId: {
          type: 'string',
          title: '上传编号',
          default: this.queryParams.sourceId
        },
        tableName: {
          type: 'string',
          title: '表名称'
        }
      }
    };
    this.req = { params: this.queryParams, lazyLoad: false };
  }

  ngOnInit() {
    this.url = this.cgExcelService.getQueryDbScriptLogUrl();
    // this.st.reset(this.queryParams);
  }
}
